var app = getApp()
// pages/order_list/order_list.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    curpage: 1,
    footprint_list: [],
    k: '',
    u: '',
    show: 0,
    request_num: 0,
    is_show_time: 1,
    list: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    new app.ToastPannel();
    var that = this
    var k = wx.getStorageSync('key')
    if (!k) {
      app.set_request('member')
    }
    if (k) {
      that.requests();

    } else {
      this.setData({
        is_show_time: 0,
      })
    }

  },


  requests: function () {
    var that = this
    var k = wx.getStorageSync('key')
    var u = wx.getStorageSync('u')

    wx.request({
      url: app.configData.shop.api_url + '/index.php?ctl=Buyer_Favorites&met=footprintwap&typ=json',
      method: 'GET',
      data: { k: k, u: u, curpage: that.data.curpage },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.status == 200) {
          that.setData({
            list: res.data.data,
            footprint_list: res.data.data.arr.items,
            k: k,
            u: u,
            is_show_time: 0
          })
        }
      }
    })
  },

  /**
     * 页面上拉触底事件的处理函数
     */
  onReachBottom: function () {
    var that = this
    var curpage = that.data.curpage + 1
    if (that.data.request_num == 1) {
      return false
    }
    wx.request({
      url: app.configData.shop.api_url + '/index.php?ctl=Buyer_Favorites&met=footprintwap&typ=json',
      method: 'GET',
      data: { k: that.data.k, u: that.data.u, curpage: curpage },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {

        if (res.data.status == 200) {
          if (res.data.data.arr.items.length > 0) {
            var footprint_list = that.data.footprint_list
            for (var z in res.data.data.arr.items) {
              footprint_list.push(res.data.data.arr.items[z])
            }

            that.setData({
              footprint_list: footprint_list,
              curpage: curpage
            })
          } else {
            that.setData({
              request_num: 1
            })
          }
        }
      }
    })
  },



  bindhref: function (e) {
    app.goTop()
    this.setData({
      show: 0
    })
  },
  //一键到顶
  onPageScroll: function (e) {
    // 获取滚动条当前位置
    var that = this
    wx.getSystemInfo({
      success: function (res) {

        if (e.scrollTop + res.windowHeight > res.windowHeight) {
          that.setData({
            show: 1
          })
        } else {
          that.setData({
            show: 0
          })
        }
      },
    })
  },
  stopDrag() {
    return false;
  },
  
  //清空
  clear: function () {
    var that = this
    wx.showModal({
      title: '',
      content: '确认清空吗？',
      success: function (res) {
        if (res.confirm) {
          wx.request({
            url: app.configData.shop.api_url + '/index.php?ctl=Buyer_Favorites&met=delFootPrint&typ=json',
            method: 'GET',
            data: { k: that.data.k, u: that.data.u },
            header: {
              'content-type': 'application/json'
            },
            success: function (res) {
              console.log(res)
              that.show(res.data.msg)
              if (res.data.status == 200) {
                that.onLoad()
              }

            }
          })
        }
      }
    })
  }
})